package com.atguigu.condition;

import com.atguigu.bean.Haha;
import com.atguigu.bean.RainBow;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Copyright 2025 ZS Network Co., Ltd. All rights reserved.
 * 本文件仅限于正数网络技术有限公司内部传阅，禁止外泄以及用于其他的商业目的。
 * Created by zwn on 2025/7/29.
 *
 * @description:
 */
public  class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     * AnnotationMetadata 当前类的注释信息
     * BeanDefinitionRegistry Bean定义的注册类
     * @param importingClassMetadata annotation metadata of the importing class
     * @param registry current bean definition registry
     *                 所有需要添加到容器中的bean，调用BeanDefinitionRegistry.registerBeanDefinition方法进行
     *                 手工注册
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        BeanDefinition definition1 = registry.getBeanDefinition("com.atguigu.bean.Red");
        BeanDefinition definition2 = registry.getBeanDefinition("com.atguigu.bean.Yellow");
        if(definition1 !=null  && definition2 != null){
            registry.registerBeanDefinition("rainBow", new RootBeanDefinition(RainBow.class));
            //registry.registerBeanDefinition("haha", new RootBeanDefinition(Haha.class));
        }
    }
}
